package tongcheng;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Hang
 * @date 2022/9/7
 * @project AutumnOffer
 * @description
 **/
public class Solution1 {
    public static void main(String[] args) {
     String level = "ababab";
        System.out.println(longestPrefix(level));
    }
    public static String longestPrefix (String s){
        Map<String,String> aftmap = new HashMap<>();
        for(int i=0;i<s.length();i++){
            aftmap.putIfAbsent(s.substring(s.length()-i),s.substring(s.length()-i));
        }
        String pre = "";
        for(int i=0;i<s.length();i++){
            if(aftmap.containsKey(s.substring(0,i))){
                pre = s.substring(0,i);
            }
        }
        return pre;
    }
}
